#include "LocalScene.h"
#include "Utils/LogUtil.h"
#include "LocalEntity.h"
#include "Utils/StringUtil.h"
#include "Game/Component/Model.h"
#include "Render/RenderState.h"
#include "Render/Imgui/imgui.h"
#include "Math/Random.h"


void LocalScene::OnInit()
{
	mNormalProcess = GetProcess<NormalProcess>("NormalProcess");
	mCoordinateProcess = GetProcess<CoordinateProcess>("CoordinateProcess");

	GeometryGenerator geometryGenerator;
	GeometryGenerator::MeshData sphereData = geometryGenerator.CreateGeosphere(0.2f, 5);

	LocalEntity* lightEntity = CreateEntity<LocalEntity>("light");
	lightEntity->AddComponent<Model>(sphereData);
	lightEntity->SetColor(glm::vec4(1.f));

	mLightAngle = 0.f;
}

void LocalScene::OnExit()
{

}

void LocalScene::OnTick(float deltaTime)
{
	mLightAngle += deltaTime;

	Entity* lightEntity = GetEntityByName("light");
	lightEntity->GetTransform().SetLocalPosition(glm::vec3(glm::sin(mLightAngle) * 5.f, 5.f, glm::cos(mLightAngle) * 5.f));
	lightEntity->GetTransform().UpdateMatrices();
}

void LocalScene::OnImgui()
{
	GameScene::OnImgui();

#if 1

	ImGui::SetNextWindowPos(ImVec2(20, 20), ImGuiCond_FirstUseEver);

	ImGui::Begin("MapOption");

	ImGui::DragFloat("U_Scale", &mNormalProcess->mUScale, 0.005f);
	ImGui::DragFloat("V_Scale", &mNormalProcess->mVScale, 0.005f);

	ImGui::InputFloat("HeightScale", &mNormalProcess->mHeightScale, 0.025f, 0.25f);
	ImGui::InputFloat("ParallaxBias", &mNormalProcess->mParallaxBias, 0.025f, 0.25f);
	ImGui::InputFloat("NumLayers", &mNormalProcess->mNumLayers, 0.025f, 0.25f);

	ImGui::RadioButton("Color", &mNormalProcess->mMappingMode, 0);
	ImGui::RadioButton("Normal", &mNormalProcess->mMappingMode, 1);
	ImGui::RadioButton("Parallax", &mNormalProcess->mMappingMode, 2);
	ImGui::RadioButton("SteepParallax", &mNormalProcess->mMappingMode, 3);
	ImGui::RadioButton("ParallaxOcclusion", &mNormalProcess->mMappingMode, 4);

	ImGui::End();

#endif
}
